// GeometryDlg.cpp : implementation file
//

#include "stdafx.h"
#include "test.h"
#include "GeometryDlg.h"
#include "CubeDlg.h"
#include "ConeDialog.h"
#include "CylinderDlg.h"
#include "SphereDlg.h"
#include "PlaneDlg.h"
#include "VRMLFilter.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGeometryDlg dialog

int CGeometryDlg::num=1;
CGeometryDlg::CGeometryDlg(std::deque<TextureName> & list,CWnd* pParent /*=NULL*/)
	: CDialog(CGeometryDlg::IDD, pParent),textures(list)
{
	//{{AFX_DATA_INIT(CGeometryDlg)
	m_malla = -1;
	//}}AFX_DATA_INIT
	mesh=NULL;
}


void CGeometryDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGeometryDlg)
	DDX_CBIndex(pDX, IDC_TYPES, m_malla);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CGeometryDlg, CDialog)
	//{{AFX_MSG_MAP(CGeometryDlg)
	ON_BN_CLICKED(IDC_SELECT_TEXTURE, OnSelectTexture)
	ON_BN_CLICKED(IDC_SELECT_FILTER, OnSelectFilter)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGeometryDlg message handlers

BOOL CGeometryDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
CListBox * list=(CListBox *)GetDlgItem(IDC_FILTERS);

	list->AddString("Filtro Cubos");	
	list->AddString("Filtro Conos");	
	list->AddString("Filtro Cilindros");
	list->AddString("Filtro Planos");	
	list->AddString("Filtro Esferas");
	list->AddString("Filtro VRML");	

	list=(CListBox *)GetDlgItem(IDC_TEXTURES);

	
	char numero[10];
	
	for(int i=0;i<textures.size();i++){
		itoa(i,numero,10);
		list->AddString(CString("Textura ")+textures[i].name);
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CGeometryDlg::OnSelectTexture() 
{
	CListBox * list=(CListBox *)GetDlgItem(IDC_TEXTURES);
	m_tex=list->GetCurSel();
	
}

void CGeometryDlg::OnSelectFilter() 
{
	Mesh3D * malla=new Mesh3D;

	CListBox * list=(CListBox *)GetDlgItem(IDC_FILTERS);
	m_filter=list->GetCurSel();	
	UpdateData(TRUE);	
	switch(m_filter){
	case 2: {CCubeDlg dlg(malla); dlg.DoModal(); malla->calculateNormals(); break;}
	case 1: {CConeDialog dlg(malla); dlg.DoModal();break;}
	case 0: {CCylinderDlg dlg(malla); dlg.DoModal(); break;}
	case 4: {CPlaneDlg dlg(malla); dlg.DoModal(); break;}
	case 3: {CSphereDlg dlg(malla); dlg.DoModal(); break;}
	case 5: {VrmlFilter filter;
			CFileDialog dlg(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,"Ficheros VRML|*.vr||");
			dlg.m_ofn.lpstrInitialDir=NULL;
			if (dlg.DoModal()==IDOK)
				filter(malla,(char *)(LPCSTR)dlg.GetPathName());
			break;}
	
	}
	
	delete mesh;
	mesh=malla;
}
